package top.lshaci.learning.netty.chat.server;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

/**
 * ServerChildHandler
 *
 * @author lshaci
 * @since 1.0.0
 */
public class ServerChildHandler extends ChannelInitializer<SocketChannel> {

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        // 得到 pipeline
        ChannelPipeline pipeline = ch.pipeline();
        // 向 pipeline 加入解码器
        pipeline.addLast("decoder", new StringDecoder());
        // 向 pipeline 加入编码器
        pipeline.addLast("encoder", new StringEncoder());
        // 加入自己的业务处理 handler
        pipeline.addLast(new GroupChatServerHandler());
    }
}
